import time
from TestCase.LoginCase import LoginCase
from Pages.PiplinePage import PiplineBuild
from PublicFunc.assertion import assertion_equal
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class PiplineCase:
    def __init__(self):
        self.service = ChromeService(executable_path=ChromeDriverManager().install())
        self.driver = webdriver.Chrome(service=self.service)

    # 流水线页面信息检查
    def test_check_info(self):
        print('=========进入流水线后页面信息检查=======')
        case1_description = '查看页面信息，是否有流水线详情标签'
        case2_description = '查看页面信息，是否有构建历史标签'
        case3_description = '查看页面信息，是否有用户管理标签'
        case4_description = '查看页面信息，流水线名称检查'
        case5_description = '查看页面信息，图标检查'
        pipline_page = PiplineBuild(self.driver)
        WebDriverWait(self.driver, 10)
        page_list = pipline_page.check_pipline_info()
        assertion_equal(page_list[0].text, '流水线详情', case1_description)
        assertion_equal(page_list[1].text, '构建历史', case2_description)
        assertion_equal(page_list[2].text, '用户管理', case3_description)
        assertion_equal(page_list[3], 1, case4_description)
        assertion_equal([page_list[4].text, page_list[5].text, page_list[6].text], ['已完成', '当前选中', '未完成'],
                        case5_description)
        print('========================================')

    # 流水线 开始 页面信息检查
    def test_check_start_info(self):
        print('=========【开始】页面信息检查=======')
        case1_description = '检查开始按钮'
        case2_description = '查看页面信息，右侧是否开始标签'
        case3_description = '查看页面信息，是否有流水线类型标签'
        case4_description = '查看页面信息，是否有流水线分组标签'
        case5_description = '查看页面信息，是否有流水线名称标签'
        case6_description = '查看页面信息，是否有镜像格式标签'
        case7_description = '查看页面信息，是否有架构标签'
        pipline_page = PiplineBuild(self.driver)
        WebDriverWait(self.driver, 10)
        page_list = pipline_page.check_start_info()
        assertion_equal(page_list[0].text, '开始', case1_description)
        assertion_equal(page_list[1].text, '开始', case2_description)
        assertion_equal(page_list[2].text, '流水线类型', case3_description)
        assertion_equal(page_list[3].text, '流水线分组', case4_description)
        assertion_equal(page_list[4].text, '流水线名称', case5_description)
        assertion_equal(page_list[5].text, '镜像格式', case6_description)
        assertion_equal(page_list[6].text, '架构', case7_description)
        print('========================================')

    def __str__(self):
        print('**镜像定制模块**')

    # 执行用例
    def run_test(self):
        self.__str__()
        self.driver.maximize_window()
        self.test_check_info()
        time.sleep(3)
        self.test_check_start_info()
        time.sleep(3)
        self.driver.quit()